﻿
using System;
using System.Collections.Generic;
using MiniWeb.Core.Dtos;
using MiniWeb.Core.Entities;
using MiniWeb.Dao;
using MiniWeb.Core.Entities;
using WFramework.MvcPager;

namespace MiniWeb.Task
{
    public class AccountsInfoTask
    {
        private readonly AccountsInfoDao _dao = new AccountsInfoDao();
        public PagedList<AccountsInfo> GetPagedList(string account, int pageIndex, int pageSize)
        {
            return _dao.GetPagedList(account,pageIndex, pageSize);
        }

        public bool Register(AccountsInfo model,out string msg)
        {
            msg = string.Empty;
            if(_dao.ExistsAccount(model.Account))
            {
                msg = "账号已存在";
                return false;
            }
            if(_dao.ExitsEmail(model.Email))
            {
                msg = "Email已存在";
                return false;
            }
            _dao.Add(model);
            return true;

        }

        public bool ExistsAccount(string account)
        {
            return _dao.ExistsAccount(account);
        }

        public bool ExitsEmail(string email)
        {
            return _dao.ExitsEmail(email);
        }

        public AccountsInfo GetByAccount(string account)
        {
            return _dao.GetByAccount(account);
        }

        public AccountsInfo GetModelByNickName(string nickname)
        {
            return _dao.GetModelByNickName(nickname);
        }
        public bool IsExiteNickName(string nickname)
        {
            return _dao.IsExiteNickName(nickname);
        }

        public AccountsInfo GetById(int id)
        {
            return _dao.GetById(id);
        }

        public void Delete(int id)
        {

            _dao.Delete(id);
        }

        public bool IsVip(string nickname)
        {
            return _dao.IsVip(nickname);
        }

        public bool Exists(int id)
        {

            return _dao.Exists(id);
        }

        public void Add(AccountsInfo model)
        {

            _dao.Add(model);
        }

        public void Update(AccountsInfo model)
        {

            _dao.Update(model);
        }

        public List<AccountsInfo> GetAll(int? top, string strwhere)
        {
            return _dao.GetAll(top, strwhere);
        }

        public AccountsInfo GetModelByUID(string uid,int sourcetype)
        {
            return _dao.GetModelByUID(uid,sourcetype);
        }
        public string CreateDateNickName()
        {
            return DateTime.Now.ToString("yyyyMMddHHmmss");
        }
        public string CreateAccount()
        {
            return DateTime.Now.ToString("yyyyMMddHHmmss");
        }




    }
}